package com.sna.snaapplication.entity.usercore.login;


import com.sna.snaapplication.entity.usercore.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

public class MyUserDetails extends User implements UserDetails {



    //该类必须有username和password属性，而User已经具有，所以无需去实现。
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //添加的代码:从角色列表role，构建属性Authorities
      return   roles.stream().map(
          role->new SimpleGrantedAuthority(role.getRoleName())).toList();
    }

    @Override
    public String getUsername() {
        return super.getUserName();
    }
}
